cmake_minimum_required(VERSION 3.8)
project(cpp_can)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)  # 新增依赖
find_package(rosidl_default_generators REQUIRED)
find_package(rosidl_typesupport_cpp REQUIRED)

# 生成消息接口
rosidl_generate_interfaces(${PROJECT_NAME}
  "msg/CarState.msg"
  DEPENDENCIES builtin_interfaces
)

add_executable(can_Init_node src/can_Init_node.cpp)
target_include_directories(can_Init_node PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>
  $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_cpp>
)
target_compile_features(can_Init_node PUBLIC c_std_99 cxx_std_17)
ament_target_dependencies(
  can_Init_node
  "rclcpp"
  "std_msgs"
  "geometry_msgs"
)
target_link_libraries(can_Init_node ${PROJECT_SOURCE_DIR}/lib/libcontrolcan.so)
rosidl_get_typesupport_target(cpp_can_typesupport_cpp
  ${PROJECT_NAME} "rosidl_typesupport_cpp")
target_link_libraries(can_Init_node ${cpp_can_typesupport_cpp})

# 添加新节点：vel_top_node
add_executable(vel_top_node src/vel_top_node.cpp)

target_include_directories(vel_top_node PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>
  $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_cpp>
)
target_compile_features(vel_top_node PUBLIC c_std_99 cxx_std_17)
ament_target_dependencies(
  vel_top_node
  "rclcpp"
  "geometry_msgs" 
)
target_link_libraries(vel_top_node ${cpp_can_typesupport_cpp})



install(TARGETS 
  can_Init_node#新增节点
  vel_top_node  # 新增节点
  DESTINATION lib/${PROJECT_NAME}
)

install(
  DIRECTORY lib/
  DESTINATION lib/${PROJECT_NAME}
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  set(ament_cmake_copyright_FOUND TRUE)
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
